//
//  XCAttentionViewController.m
//  XCNewsApp
//
//  Created by FAITH on 16/12/6.
//  Copyright © 2016年 XC. All rights reserved.
//

#import "XCAttentionViewController.h"
#import "FAITHHttpTool.h"
#import "XCAttentionSearcherViewController.h"
@interface XCAttentionViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,weak) UITableView *tableView;
@end

@implementation XCAttentionViewController
static NSString * const KattentionTopCellID=@"attentionTopCellID";
static NSString * const KattentionBottomCellID=@"KattentionBottomCellID";

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
  
    [self setUpNavBar];
    
    [self setUpUI];
    
    self.tableView.rowHeight=66;
    
}

-(void)setUpNavBar
{
    self.navigationItem.rightBarButtonItem=[UIBarButtonItem itemWithImageName:@"search_subscibe_titilebar" highImageName:@"search_subscibe_titilebar_press" target:self action:@selector(searchBtnClick)];
}

-(void)searchBtnClick
{
    XCAttentionSearcherViewController *search=[[XCAttentionSearcherViewController alloc] init];
    
    [self.navigationController pushViewController:search animated:YES];
}

-(void)setUpUI
{
    UITableView *tableView=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH) style:UITableViewStyleGrouped];
    
    [self.view addSubview:tableView];
    
    self.tableView=tableView;
    
    tableView.delegate=self;
    
    tableView.dataSource=self;
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:KattentionTopCellID];
    
    self.tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    
    self.tableView.contentInset=UIEdgeInsetsMake(-35, 0, 0, 0);
    
    self.tableView.backgroundColor=[UIColor whiteColor];
}


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section==0) {
        return 1;
    } else
    {
        return 0;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:KattentionTopCellID];
    
    cell.imageView.image=[UIImage imageNamed:@"neihan_dynamic"];
    
    cell.textLabel.text=@"好友动态";
    
    return cell;
}




-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    NSDictionary *params= @{
                            @"version_code" : @"5.8.5",
                            @"app_name" : @"news_article",
                            @"vid" : @"AE8B93E7-AF12-497D-B605-E394BECCA2B9",
                            @"device_id" : @"10723815300",
                            @"channel" : @"App%20Store",
                            @"resolution" : @"1242*2208",
                            @"aid" : @"13",
                            @"ab_version" : @"90171,83097,89186,87331,93903,93822,94055,93419,92848,93981,94006,82679,93319,92439,93526,93357,92518,94005,92485,87495,93888,87988",
                            @"ab_feature" : @"z2",
                            @"ab_group" : @"z2",
                            @"openudid" : @"d41d8cd98f00b204e9800998ecf8427ef2339ea7",
                            @"live_sdk_version" : @"1.3.0",
                            @"idfv" : @"AE8B93E7-AF12-497D-B605-E394BECCA2B9",
                            @"ac" : @"WIFI",
                            @"os_version" : @"9.1",
                            @"ssmix" : @"a",
                            @"device_platform" : @"iphone",
                            @"iid" : @"6314617356",
                            @"ab_client" : @"a1,f2,f7,e1",
                            @"device_type" : @"iPhone%206%20Plus",
                            @"idfa" : @"4BAD76A0-89BD-41EA-92EC-92FF39DBAAE1",
                            @"LBS_status" : @"authroize",
                            @"city" : @"%E5%B9%BF%E5%B7%9E",
                            @"concern_id" : @"6286225228934679042",
                            @"count" : @"20",
                            @"cp" : @"5a814a639d038q1",
                            @"detail" : @"1",
                            @"image" : @"1",
                            @"language" : @"zh-Hans-CN",
                            @"last_refresh_sub_entrance_interval" : @"1481019448",
                            @"latitude" : @"23.1331997900028",
                            @"loc_mode" : @"1",
                            @"loc_time" : @"1481019127",
                            @"longitude" : @"113.3674360500047",
                            @"min_behot_time" : @"1481019411",
                            @"refer" : @"1",
                            @"strict" : @"0",
                            @"tt_from" : @"pull HTTP/1.1"
                           
                            };
    
    [FAITHHttpTool get:@"http://lg.snssdk.com/api/news/feed/v46" params:params success:^(id responseObj) {
   
        NSArray *dataArray=responseObj[@"data"];
        
        
        NSDictionary *dict=dataArray[0];
        

        NSString *content= dict[@"content"];
        
        NSLog(@"%@",content);

        NSData *data=[content dataUsingEncoding:NSUTF8StringEncoding];
        
        NSDictionary *dict2=[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];

        
//        NSLog(@"%@",dict2[@"title"]);
        
         [dict2 writeToFile:@"/Users/FAITH/Desktop/SVN/data.plist" atomically:YES];
        
    } failure:^(NSError *error) {
//
    } ];


}


@end
